package isanfeng.tuxiaoer.pattern.creational.Esingleton.hungry;

import java.io.*;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

/**
 * 序列化和反序列化不是同一个对象
 * @author 李红辉
 * @version 1.0
 * @date 2019/10/9 16:14
 */
public class Test {
//    public static void main(String[] args) throws IOException, ClassNotFoundException {
//        HungrySingleton instance = HungrySingleton.getInstance();
//
//        File file = new File("singleton_file");
//
//        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(file));
//        oos.writeObject(instance);
//
//        ObjectInputStream ois = new ObjectInputStream(new FileInputStream(file));
//        HungrySingleton newInstance = (HungrySingleton) ois.readObject();
//
//        System.out.println(instance);
//        System.out.println(newInstance);
//        System.out.println(instance == newInstance);
//    }
//    public static void main(String[] args) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
//        HungrySingleton instance = HungrySingleton.getInstance();
//
//        Class objectClass = HungrySingleton.class;
//        Constructor constructor = objectClass.getDeclaredConstructor();
//        // 放开私有构造器权限
//        constructor.setAccessible(true);
//        HungrySingleton newInstance = (HungrySingleton) constructor.newInstance();
//
//        System.out.println(instance);
//        System.out.println(newInstance);
//        System.out.println(instance == newInstance);
//
//    }
    public static void main(String[] args) {
        EnumInstance enumInstance = EnumInstance.getInstance();
        enumInstance.printTest();
    }
}
